home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / WASTE 1.2 / WASTE Demo ƒ / WEDemoIntf.h < prev    next >
Text File  |  1996-06-20  |  9KB  |  415 lines

  1. /*
  2.     WASTE Demo Project:
  3.     Demo Header
  4.  
  5.     Copyright © 1993-1996 Marco Piovanelli
  6.     All Rights Reserved
  7.  
  8.     C port by John C. Daub
  9. */
  10.  
  11. /*
  12.     Due to differences between Pascal and C, this file (nothing like it originally existed
  13.     in the original Pascal code) was neccessary to create.  In it contains various macros,
  14.     constants, type and class declarations, function prototypes, etc..  From the original
  15.     code, some of this material would be spread amongst the source files, but a good
  16.     majority of this file comes from the WEDemoIntf.p file (the declarations, constants, etc).
  17.     There still is a WEDemoIntf.c file in the project tho since the .p file had a few
  18.     utility functions declared and defined in it.
  19. */
  20.  
  21. #ifndef __WEDEMOAPP__
  22. #define __WEDEMOAPP__
  23.  
  24. #ifndef __TYPES__
  25. #include <Types.h>
  26. #endif
  27. #ifndef __RESOURCES__
  28. #include <Resources.h>
  29. #endif
  30. #ifndef __QUICKDRAW__
  31. #include <QuickDraw.h>
  32. #endif
  33. #ifndef __MENUS__
  34. #include <Menus.h>
  35. #endif
  36. #ifndef __WINDOWS__
  37. #include <Windows.h>
  38. #endif
  39. #ifndef __CONTROLS__
  40. #include <Controls.h>
  41. #endif
  42. #ifndef __STANDARDFILE__
  43. #include <StandardFile.h>
  44. #endif
  45. #ifndef _WASTE_
  46. #include "WASTE.h"
  47. #endif
  48. #ifndef _LIMITS
  49. #include "limits.h"
  50. #endif
  51.  
  52.  
  53. /*
  54.  *    Some utility macros.
  55.  */
  56.  
  57.  
  58.  
  59. //     "Originally," these are things built into the Pascal language
  60. //     but since C doesn't have anything like them, and in an attempt to keep the code readable
  61. //     and similar to the original Pascal source, these #define macros work nice.
  62.  
  63.  
  64. #define BTST( FLAGS, BIT )    (((FLAGS) & (1L << (BIT))) ? 1 : 0)
  65. #define BSET( FLAGS, BIT )  ((FLAGS) |= (1L << (BIT)))
  66. #define BCLR( FLAGS, BIT )  ((FLAGS) &= (~(1L << (BIT))))
  67.  
  68. #define ABS(A) ((A) > 0 ? (A) : -(A))
  69.  
  70. #define BSL(A, B)    (((long) (A)) << (B))
  71. #define BSR(A, B)    (((long) (A)) >> (B))
  72. #define BOR(A, B)    ((A) | (B))
  73. #define BAND(A, B)    ((A) & (B))
  74.  
  75. #ifndef HiWrd
  76. #define HiWrd(aLong)        (((aLong) >> 16) & 0xFFFF )
  77. #endif
  78. #ifndef LoWrd
  79. #define LoWrd(aLong)        ((aLong) & 0xFFFF )
  80. #endif
  81.  
  82. enum {
  83.  
  84. //    WASTE Demo signature
  85.  
  86.     sigWASTEDemo        =        'OEDE',
  87.  
  88. //    resource types, clipboard types, and file types
  89.  
  90.     kTypeDeskAccessory    =        'DRVR',
  91.     kTypeFont            =        'FONT',
  92.     kTypePicture        =        'PICT',
  93.     kTypeSound            =        'snd ',
  94.     kTypeSoup            =        'SOUP',
  95.     kTypeStyles            =        'styl',
  96.     kTypeText            =        'TEXT'
  97. };
  98.  
  99. enum {
  100.  
  101. //    virtual key codes for navigation keys found on extended keyboards
  102.  
  103.     keyPgUp                =        0x74,
  104.     keyPgDn                =        0x79,
  105.     keyHome                =        0x73,
  106.     keyEnd                =        0x77,
  107.  
  108. //    virtual key codes generated by some function keys
  109.  
  110.     keyF1                =        0x7A,
  111.     keyF2                =        0x78,
  112.     keyF3                =        0x63,
  113.     keyF4                =        0x76
  114. };
  115.  
  116. //    possible values for HandleOpenDocument refCon parameter
  117.  
  118. enum {
  119.     kDoOpen        = 0,
  120.     kDoPrint    = 1
  121. };
  122.  
  123. //     other commonly used constants
  124.  
  125. #define    kBarWidth        16        // width of a scroll bar
  126. #define kTitleHeight    20        // usual height of a window title bar
  127. #define kTextMargin        3        // indent of text rect from a window port rect
  128. #define kScrollDelta    11        // pixels to scroll when the scroll bar arrow is clicked
  129.  
  130. #define kMinSystemVersion        0x0700    // system 7
  131. #define kScrapThreshold            4 * 1024
  132.  
  133. // enumeration types used for closing a window and/or quitting the application
  134.  
  135. typedef enum {closingWindow, closingApplication} ClosingOption;
  136. typedef enum {savingYes, savingNo, savingAsk} SavingOption;
  137.  
  138.  
  139. /*
  140.  *    Resource ID numbers
  141.  */
  142.  
  143. // menu IDs
  144.  
  145. enum {
  146.     kMenuApple        = 1,
  147.     kMenuFile,
  148.     kMenuEdit,
  149.     kMenuFont,
  150.     kMenuSize,
  151.     kMenuStyle,
  152.     kMenuColor,
  153.     kMenuFeatures,
  154.     kMenuAlignment
  155. };
  156.  
  157. //    Apple Menu items
  158.  
  159. enum {
  160.     kItemAbout        = 1
  161. };
  162.  
  163. //    File menu items
  164.  
  165. enum {
  166.     kItemNew        = 1,
  167.     kItemOpen        = 2,
  168.     kItemClose        = 4,
  169.     kItemSave        = 5,
  170.     kItemSaveAs        = 6,
  171.     kItemQuit        = 8
  172. };
  173.  
  174. //    Edit menu items
  175.  
  176. enum {
  177.     kItemUndo        = 1,
  178.     kItemCut        = 3,
  179.     kItemCopy        = 4,
  180.     kItemPaste        = 5,
  181.     kItemClear        = 6,
  182.     kItemSelectAll    = 7
  183. };
  184.  
  185. //    Size menu items
  186.  
  187. enum {
  188.     kItemLastSize    = 6,
  189.     kItemSmaller    = 8,
  190.     kItemLarger        = 9
  191. };
  192.  
  193. //    Style menu items
  194.  
  195. enum {
  196.     kItemPlainText    = 1,
  197.     kItemBold,
  198.     kItemItalic,
  199.     kItemUnderline,
  200.     kItemOutline,
  201.     kItemShadow,
  202.     kItemCondensed,
  203.     kItemExtended
  204. };
  205.  
  206. //    Color menu items
  207.  
  208. enum {
  209.     kItemBlack        = 1,
  210.     kItemRed,
  211.     kItemGreen,
  212.     kItemBlue,
  213.     kItemCyan,
  214.     kItemMagenta,
  215.     kItemYellow
  216. };
  217.  
  218. //    Alignment menu items
  219.  
  220. enum {
  221.     kItemAlignDefault    = 1,
  222.     kItemAlignLeft        = 3,
  223.     kItemCenter,
  224.     kItemAlignRight,
  225.     kItemJustify
  226. };
  227.  
  228. //    Features menu items
  229.  
  230. enum {
  231.     kItemAlignment        = 1,
  232.     kItemTabHooks,
  233.     kItemAutoScroll        = 4,
  234.     kItemOutlineHilite,
  235.     kItemReadOnly,
  236.     kItemIntCutAndPaste,
  237.     kItemDragAndDrop,
  238.     kItemOffscreenDrawing
  239. };
  240.  
  241.  
  242. //    Alert & dialog template resource IDs
  243.  
  244. enum {
  245.     kAlertNeedSys7        = 128,
  246.     kAlertGenError        = 130,
  247.     kAlertSaveChanges    = 131,
  248.     kDialogAboutBox        = 256
  249. };
  250.  
  251. //    String list resource IDs
  252.  
  253. enum {
  254.     kUndoStringsID        = 128,
  255.     kClosingQuittingStringsID
  256. };
  257.  
  258. // miscellaneous resource IDs
  259.  
  260. enum {
  261.     kMenuBarID                = 128,
  262.     kWindowTemplateID        = 128,
  263.     kScrollBarTemplateID    = 128,
  264.     kPromptStringID            = 128
  265. };
  266.  
  267. // a DocumentRecord is a structure associated with each window
  268. // a handle to this structure is kept in the window refCon
  269.  
  270. struct DocumentRecord
  271. {
  272.     WindowRef            owner;                // the window
  273.     ControlRef            scrollBars [ 2 ];    // its scroll bars
  274.     WEReference         we;                    // its WASTE instance
  275.     Handle                 fileAlias;            // alias to associated file
  276. };  // DocumentRec
  277.  
  278. typedef struct DocumentRecord DocumentRecord, *DocumentPtr, **DocumentHandle;
  279.  
  280.  
  281. /*
  282.  *    The external declaration of some global variables.
  283.  */
  284.  
  285. //  These are defined in WEDemoIntf.c
  286.  
  287. extern    Boolean        gHasColorQD;        // true if Color QuickDraw is available
  288. extern    Boolean        gHasDragAndDrop;    // true if Drag Manager is available
  289. extern    Boolean        gHasTextServices;    // true is the Text Services Manager is available
  290. extern    Boolean        gExiting;            // set this variable to drop out of the event loop and quit
  291.  
  292. /*
  293.  *    Function Prototypes
  294.  */
  295.  
  296. //    From DialogUtils.c
  297.  
  298. ModalFilterUPP    GetMyStandardDialogFilter( void );
  299. short            GetDialogItemType( DialogRef, short );
  300. Handle            GetDialogItemHandle( DialogRef, short );
  301. void            GetDialogItemRect( DialogRef, short, Rect * );
  302. void            SetDialogItemProc( DialogRef, short, UserItemUPP );
  303. void            FlashButton( DialogRef, short );
  304.  
  305. //    From LongControls.c
  306.  
  307. OSErr            LCAttach( ControlRef );
  308. void            LCDetach( ControlRef );
  309. void            LCSetValue( ControlRef, long );
  310. void            LCSetMin( ControlRef, long );
  311. void            LCSetMax( ControlRef, long );
  312. long            LCGetValue( ControlRef );
  313. long            LCGetMin( ControlRef );
  314. long            LCGetMax( ControlRef );
  315. void            LCSynch( ControlRef );
  316.  
  317.  
  318. //    From WEDemoIntf.c
  319.  
  320. DocumentHandle    GetWindowDocument(WindowRef);
  321. #if __cplusplus
  322. inline WEReference GetWindowWE(WindowRef window) { return (* GetWindowDocument(window))->we; }
  323. #else
  324. #define GetWindowWE(window) (* GetWindowDocument(window))->we
  325. #endif
  326. void            ErrorAlert( OSErr );
  327. void            ForgetHandle( Handle * );
  328. void            ForgetResource( Handle * );
  329. OSErr            NewHandleTemp( Size, Handle * );
  330. void            PStringCopy( ConstStr255Param, Str255 );
  331.  
  332. //    From WEDemoAbout.c
  333.  
  334. OSErr            WETextBox( short, const Rect *, WEAlignment );
  335. void            DoAboutBox( short );
  336.  
  337. //    From WEDemoDrags.c
  338.  
  339. OSErr            InstallDragHandlers( void );
  340. OSErr            RemoveDragHandlers( void );
  341.  
  342. //    From WEDemoEvents.c
  343.  
  344. void            AdjustCursor( Point, RgnHandle );
  345. void            DoMouseDown( const EventRecord * );
  346. void            DoKeyDown( const EventRecord * );
  347. void            DoDiskEvent( const EventRecord * );
  348. void            DoOSEvent( const EventRecord * );
  349. void            DoHighLevelEvent( const EventRecord * );
  350. void            DoNullEvent( const EventRecord * );
  351. void            DoWindowEvent( const EventRecord *);
  352. void            ProcessEvent( void );
  353. OSErr            GotRequiredParams( const AppleEvent * );
  354. OSErr            InitializeEvents( void );
  355.  
  356. // from WEDemoFiles.c
  357.  
  358. OSErr            ReadTextFile( const FSSpec *, WEReference );
  359. OSErr            WriteTextFile( const FSSpec *, WEReference );
  360. pascal OSErr    TranslateDrag( DragReference, ItemReference, FlavorType, Handle );
  361. pascal OSErr    CheckObjectLock( short, long, StringPtr );
  362. pascal OSErr    FSpCheckObjectLock( const FSSpec * );
  363.  
  364. // from WEDemoInit.c
  365.  
  366. OSErr            Initialize( void );
  367. void            Finalize( void );
  368.  
  369. // from WEDemoMenus.c
  370.  
  371. void            SetDefaultDirectory( const FSSpec * );
  372. short            FindMenuItemText( MenuRef, ConstStr255Param );
  373. Boolean            EqualColor( const RGBColor *, const RGBColor * );
  374. void            PrepareMenus( void );
  375. void            DoDeskAcc( short );
  376. OSErr            DoNew( void );
  377. OSErr            DoOpen( void );
  378. OSErr            SaveWindow( const FSSpec *, WindowRef );
  379. OSErr            DoSaveAs( const FSSpec *, WindowRef );
  380. OSErr            DoSave( WindowRef );
  381. OSErr            DoClose( ClosingOption, SavingOption, WindowRef );
  382. OSErr            DoQuit( SavingOption );
  383. void            DoAppleChoice( short );
  384. void            DoFileChoice( short );
  385. void            DoEditChoice( short );
  386. void            DoFontChoice( short, EventModifiers );
  387. void            DoSizeChoice( short );
  388. void            DoStyleChoice( short );
  389. void            DoColorChoice( short );
  390. void            DoAlignChoice( short );
  391. void            DoFeatureChoice( short );
  392. void            DoMenuChoice( long, EventModifiers );
  393. OSErr            InitializeMenus( void );
  394.  
  395. // from WEDemoScripting.c
  396.  
  397. OSErr            WEGetContentsDesc( long, long, Boolean, AEDesc *, WEReference );
  398. OSErr            WESetContentsDesc( long, long, const AEDesc *, WEReference );
  399. OSErr            InstallCoreHandlers( void );
  400.  
  401. // from WEDemoWindows.c
  402.  
  403. void            DoDrag( Point, WindowRef );
  404. void            DoGrow( Point, WindowRef );
  405. void            DoZoom( short, WindowRef );
  406. Boolean            DoContent( Point, const EventRecord *, WindowRef );
  407. void            DoKey( short, const EventRecord * );
  408. void            DoUpdate( WindowRef );
  409. void            DoActivate( Boolean, WindowRef );
  410. OSErr            CreateWindow( const FSSpec * );
  411. void            DestroyWindow( WindowRef );
  412. void            Resize( Point, WindowRef );
  413.  
  414.  
  415. #endif /* __WEDEMOAPP__ */